<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>后台登录 - 内容管理系统</title>
<link rel="stylesheet" href="/static/admin/css/dashicons.css">
<link rel="stylesheet" href="/static/admin/css/layout.css">
	<script src="/static/index/js/jquery.2.1.4.min.js"></script>
<script>
if(top.location !== self.location){ 
	top.location = self.location; 
}
</script>
</head>
<body>
<div class="top">
<div class="top-title icon-home">内容管理系统</div>
<div class="top-right">
	<a href="../" target="_blank">前台首页</a>
</div>
</div>
<div class="login">
<div class="login-wrap">
	<a href="../" target="_blank" class="login-logo" title="点击查看前台首页"></a>
	<div class="tips"></div>
	<div class="login-box">
<!--		<form method="post" action="login.php?token=9709922e308351f63ba18f2271f2d4e7">-->
		<table>
			<tr>
				<th>账号：</th>
				<td><input type="text" name="name" value="" autocomplete="off"></td>
			</tr>
			<tr >
				<th>密码：</th>
				<td><input type="password" name="password" autocomplete="off"></td>
			</tr>
			<input type="hidden" name="__token__" value="{$Request.token}"/>
			<tr id="myTr" style="display:none" >
				<th>验证码：</th>
				<td><input type="text" name="captcha" autocomplete="off"></td>
			</tr>
			<tr id="myYzm" style="display:none">
				<th></th>
				<td><img src="{:captcha_src()}" id="captcha" alt="验证码" title="点击刷新验证码"></td>
			</tr>
			<input type="hidden" name="__token__" value="{$Request.token}" />
			<tr>
				<th></th>
				<td><input type="submit" onclick="login()" value="登录"></td>
			</tr>
		</table>
<!--		</form>-->

	</div>
</div>
</div>
<script>
//验证码点击刷新
(function(){
	var $img = $("#captcha");
	var src = $img.attr("src")+"?_=";
	$img.click(function(){
		$img.attr("src",src+Math.random()); //添加随机数防止浏览器缓存图片
	});
})();

function login(){
	if($('[name="name"]').val() == ""){
		return alert('账号不能为空');
	}
	if($('[name="password"]').val() == ""){
		return alert('密码不能为空');
	}
	$.ajax({
		type:'POST',
		url:'login',
		data:{
			nickname:$('input[name="name"]').val(),
			password:$('input[name="password"]').val(),
			captcha:$('input[name="captcha"]').val(),
			__token__  :$("input[name=__token__]").val(),//令牌
		},
		success:function (res){
			if(res.code == 0){
				if(res.data >= 3){
					$('#myTr').show();
					$('#myYzm').show();
				}
				alert(res.msg);
			}else{
				alert(res.msg);
				setTimeout(()=>{
					window.location='http://www.cms.com/index.php/home/login/index';
				},100);
			}
		}
	})
}
</script>
</body>
</html>